Skip to content

Avoid fixed-size filename buffers in the binary and ASCII restart readers - #3001

Merged
bigfooted merged 3 commits into
su2code:developfrom
Syphonicc:fix-restart-filename-buffers
Nov 30, 2026
Merged

bigfooted merged 3 commits into
su2code:developfrom
Syphonicc:fix-restart-filename-buffers

Conversation

@Syphonicc

Copy link
Copy Markdown
Contributor

Proposed Changes

The binary restart readers copy a user-controlled filename into a fixed char fname[100] with
strcpy, which has no bounds check. The filename comes from the config (SOLUTION_FILENAME and the
derived restart/mesh names), so a path longer than 99 characters overflows the stack buffer.

This replaces the fixed buffer and strcpy with a const char* fname = <filename>.c_str(); at each
site. The string is already in scope and is not modified between this point and the file open, so the
behaviour is identical; only the fixed-size copy is removed. All use sites (fopen, MPI_File_open,
and the error messages) are unchanged.

Sites fixed (all were char fname[100]):

  • CSolver::Read_SU2_Restart_ASCII and CSolver::Read_SU2_Restart_Binary
  • CBaselineSolver::Load_Restart (binary and ASCII branches)
  • CBaselineSolver_FEM::Load_Restart (binary and ASCII branches)
  • CPhysicalGeometry::SetBoundaries restart readers (binary and ASCII branches)

Verification

  • Reproduced the overflow before the change with an AddressSanitizer build: pointing
    SOLUTION_FILENAME at a ~150-character path aborts with a stack-buffer-overflow in
    Read_SU2_Restart_Binary (the write into fname). After the change the same case runs cleanly
    under ASAN.
  • axi_rans_air_nozzle_restart (reads a binary restart) reproduces the stored regression values
    exactly, confirming the readers are unaffected. The change is non-numerical, so no regression
    values change.
  • No new compiler warnings.

There is one related spot left out of this PR to keep it focused: the surface-sensitivity reader in
CPhysicalGeometry uses cstr[MAX_STRING_SIZE] with strcpy/strcat (400 bytes, a different
function). Happy to address it here or in a follow-up, whichever is preferred.

Related Work

None.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@bigfooted bigfooted changed the title Avoid fixed-size filename buffers in the binary restart readers Avoid fixed-size filename buffers in the binary and ASCII restart readers Nov 30, 2026

@bigfooted bigfooted left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Please also address the remaining buffer issue in a follow PR or create an issue ticket.

@bigfooted
bigfooted merged commit ed5b374 into su2code:develop Nov 30, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants